require 'simple-rss'
require 'open-uri'

class ShowRss
  attr_reader :errors, :episodes
  def initialize(url)
    @valid = nil
    @rss = nil
    @url = url
    @errors = []
    @episodes = []
    
    get_rss_content
    
    parse_episodes if valid?
  end
  
  def reload
    get_rss_content
  end
  
  def valid?
    return @valid
  end
  
  def parse_episodes
    @rss.items.each do |item|
      @episodes << item
    end
  end
  
  private
  
  def get_rss_content
    begin
      @rss = SimpleRSS.parse open(@url)
      @valid = true unless @rss.nil?
    rescue Exception  => e
      @valid = false
      @errors << e
    end    
  end
  
end